<?php
class OrderServer {
	public function pagingBySearch($where="",$order='',$numberEachPage = 10,$page_search=array()){
		$count = HttpDaoManager::getOrderDao()->searchNumber($where);
		if(isset($page_search)&&!empty($page_search)){
			$page = new Page($count, $numberEachPage,$page_search['page_par']);
		}else{
			$page = new Page($count, $numberEachPage);
		}
		$limit[0]= $page->which;
		$limit[1]=$numberEachPage;
		$order = "order by id desc";
		$list = HttpDaoManager::getOrderDao()->searchList($where,$order, $limit);
		if(isset($page_search)&&!empty($page_search)){
			$page1= $page->returnPage("?&".$page_search['page_par']."=");
		}else{
			$page1= $page->returnPage("?".ClassManager::getToos()->combinationGet('page')."&page=");
		}
		$data['list'] =$list;
		$data['page'] = $page1;
		return $data;
	}
	public function lists ($where=array(),$order='',$numberEachPage = 10){
		if (!empty($where['phone'])){
			$userData = HttpDaoManager::getUserDao()->searchList(array('phone'=>$where['phone']));
			if (!empty($userData)){
				$where['user_id'] = $userData['id'];
			}
		}
		$order = ' order by id desc';
		$data = $this->pagingBySearch($where,$order,$numberEachPage);
		$orderStatus = Common::_t('order_status');
		$payType = Common::_t('pay_type');
		$payStatus = Common::_t('pay_status');
		$data['payTypeOption'] = page_modifier_options($payType,$where['pay_type']);
		$data['payStatusOption'] = page_modifier_options($payStatus,$where['pay_status']);
		$list = $data['list'];
		unset($data['list']);
		$userId = array();
		$productIdArray = array();
		$orderLogDao = HttpDaoManager::getOrderLogDao();
		foreach ($list as $k=>$v){
			$list[$k]['order_status'] = $orderStatus[$v['order_status']];
			$userId[] = $v['user_id'];
			$list[$k]['pay_type'] = $payType[$v['pay_type']];
			$list[$k]['pay_type_name'] = $payType[$v['pay_type']];
			$list[$k]['pay_status_name'] = $payStatus[$v['pay_status']];
			$tmp   =  strtr($v['product_id'],array('|'=>''));
			$list[$k]['product_id'] = explode(',',$tmp);
			$productIdArray  = array_merge($productIdArray,$list[$k]['product_id']);
			$list[$k]['do'] = $orderLogDao->searchData(array('order_id'=>$v['id'],'type'=>ORDER_STATUS_1));
			$preferentialArray = array();
			$preferentialMoneyArray = array();
			if ($v['ticket_money']!=0){
				$preferentialArray[] = "优惠劵";
				$preferentialMoneyArray[]="优惠劵".$v['ticket_money']."元";
			}
			if ($v['discount_money']!=0){
				$preferentialArray[] = "折扣";
				$preferentialMoneyArray[]="折扣".$v['discount_money']."元";
			}
			if(!empty($preferentialArray)){
				$list[$k]['preferential'] = implode('<br/>',$preferentialArray);
			}
			if(!empty($preferentialMoneyArray)){
				$list[$k]['preferentialMoney'] = implode('<br/>',$preferentialMoneyArray);
			}
		}
		$data['list'] = $list;
		if(!empty($userId)){
			$userList = HttpDaoManager::getUserDao()->searchList1(array('id'=>array(implode(',',$userId),'in')));
			unset($userId);
			$data['userList'] = array();
			foreach ($userList as $v){
				if(isset($v['english_name'])&&!empty($v['english_name'])){
					$data['userList'][$v['id']] = $v['english_name'];
				}elseif(isset($v['email'])&&!empty($v['email'])){
					$data['userList'][$v['id']] = $v['email'];
				}
			}
			unset($userList);
		}
		if(!empty($productIdArray)){
			$productList = HttpDaoManager::getProductDao()->searchList(array('id'=>array(implode(',',$productIdArray),'in')));
			unset($productIdArray);
			$data['productList'] = array();
			foreach ($productList as $v){
				$data['productList'][$v['id']]=$v['name'];
			}
			unset($productList);
		}
		return $data;
	}
	
	
	public function updateOrderStatus($id,$OrderStatus,$add_admin,$remark){
		$orderDao = HttpDaoManager::getOrderDao();
		$data = $orderDao->get($id);
		if ($data['order_status']!=$OrderStatus){
			HttpDaoManager::getOrderDao()->update(array('order_status'=>$OrderStatus), $id);
			HttpDaoManager::getOrderLogDao()->add(array('order_id'=>$id,'type'=>$OrderStatus,'add_time'=>time(),'add_admin'=>$add_admin,'remark'=>$remark));
		}
	}
	
	public function add($data){
		$data['order_no'] = $this->getOrderNo();
		$data['add_time'] = time();
		return HttpDaoManager::getOrderDao()->add($data);
		
	}


	public function saveRemark($id,$remark =''){
		$tmp = array(
				'type' =>ORDER_LOG_TYPE_5,
				'remark' =>$remark,
				'order_id' => $id,
				'add_time' =>time(),
				'add_admin' =>$_SESSION['admin']['name']
		);
		HttpDaoManager::getOrderLogDao()->add($tmp);
	}

	public function confirm($id,$remark =''){
		$data = array(
				'confirm_admin'=> $_SESSION['admin']['name'],
				'confirm_time'=> time(),
				'order_status'=>ORDER_STATUS_1
		);

		HttpDaoManager::getOrderDao()->update($data, $id);
		$tmp = array(
				'type' =>ORDER_LOG_TYPE_1,
				'remark' =>$remark,
				'order_id' => $id,
				'add_time' =>time(),
				'add_admin' =>$_SESSION['admin']['name']
		);
		HttpDaoManager::getOrderLogDao()->add($tmp);
	}
	
	public function cancel($id,$remark =''){
		$data = array(
				'cancel_user'=> $_SESSION['admin']['name'],
				'cancel_time'=> time(),
				'order_status'=>ORDER_STATUS_3
		);

		HttpDaoManager::getOrderDao()->update($data, $id);
		$tmp = array(
				'type' =>ORDER_LOG_TYPE_3,
				'remark' =>$remark,
				'order_id' => $id,
				'add_time' =>time(),
				'add_admin' =>$_SESSION['admin']['name']
		);
		HttpDaoManager::getOrderLogDao()->add($tmp);
	}
	
	/**
	 *完成订单 
	 */
	public function complete($id,$remark =''){
		$data = array(
				'complete_admin'=> $_SESSION['admin']['name'],
				'complete_time'=> time(),
				'order_status'=>ORDER_STATUS_2
// 				'transaction_no'  =>$transactionNo
		);
		$orderDao = HttpDaoManager::getOrderDao();
		$orderDao->update($data, $id);
		$tmp = array(
			'type' =>ORDER_LOG_TYPE_2,
			'remark' =>$remark,
			'order_id' => $id,
			'add_time' =>time(),
			'add_admin' =>$_SESSION['admin']['name']
		);
		HttpDaoManager::getOrderLogDao()->add($tmp);
		$orderData  = $orderDao->get($id);
		
		//更新用户信息

		//最好发个短信

		//更新用户日志信息
		$integral = array(
			'integral' => $orderData['order_amount'],
			'user_id' => $orderData['user_id'],
			'type' => INTEGRAL_TYPE_1
		);
		HttpServerManager::getUserServer()->updateIntegral($integral);
		HttpServerManager::getTeacherLogServer()->payReward($orderData['user_id'], 'system');//给予上体验课老师奖励
	}	
	public function getOrderNo(){
		$orderNo = 'CO'.ClassManager::getToos()->new_sn();
		$tmp =  HttpDaoManager::getOrderDao()->getByOrderNo($orderNo);
		if (!empty($tmp)){
			$orderNo =  $this->getOrderNo();
		}
		return  $orderNo;
	}
	public function pay($data,$id){
		$data['pay_status'] = PAY_STATUS_2;
		$data['pay_time'] = time();
		HttpDaoManager::getOrderDao()->update($data, $id);
		$orderData = HttpDaoManager::getOrderDao()->get($id);//更新支付状态
		
		$userId = $orderData['user_id'];
		$productId =  strtr($orderData['product_id'],array('|'=>''));
		$productList = HttpDaoManager::getProductDao()->getListInId($productId);
		$userDao =  HttpDaoManager::getUserDao();
		$userData = $userDao->get($userId);
		$old_user_type = $userData['user_type'];
		$invite_user_id = $userData['user_id'];
		$old_user_class = $userData['user_class'];
		
		$productBookType = Common::_t('product_book_type');
		$classPeriodValidity = Common::_t('class_period_validity');
		
		$ticket_favour_array = array();
		foreach ($productList as $k=> $v){
			$userData[$productBookType[$v['type']]] = $userData[$productBookType[$v['type']]] + $v['lesson'];
			if ($userData[$classPeriodValidity[$v['type']]]==0){
				$tmp =  strtotime(date('Y-m-d'));
			}
			else{
				$tmp  = $userData[$classPeriodValidity[$v['type']]];
			}
			$userData[$classPeriodValidity[$v['type']]] =$tmp+86400+$v['period_validity']*86400;
			$ticket_favour_array[$k]['return_ticket'] = $v['return_ticket'];
// 			$ticket_favour_array[$k]['product_info']['period_validity'] = $v['period_validity'];
		}
		
		if($old_user_type!=USER_TYPE_MONEY){
			$userData['user_type'] = USER_TYPE_MONEY;
		}
		
		$userDao->update($userData, $userId);
		
		//返回券
		foreach($ticket_favour_array as $k1=>$v1){
			$return_product_id = $v1['return_ticket'];
			HttpServerManager::getTicketServer()->favourTicketSend($userId, $return_product_id, 1);
			
		}
		
		$order_where = array();
		$order_where['user_id'] = $invite_user_id;
		$order_where['pay_status'] = PAY_STATUS_2;
		
		$order_list = HttpDaoManager::getOrderDao()->searchNumber($where);
		//奖励次卡
		if(count($order_list)==1&&$invite_user_id>0){//被邀请过来
			$this->sendInviterFavour($userId);
		}
		return true;
	}
	
	public function sendInviterFavour($userId){
		$user_info = HttpDaoManager::getUserDao()->get($userId);
		$user_class = $user_info['user_class']+1;//
		if($user_info['user_class']>0){
			$user_class_period_validity =strtotime("+ 3 day",$user_info['class_period_validity']);
		}else{
			$user_class_period_validity =strtotime("+ 3 day",strtotime(date('Y-m-d')));
		}
		
		$update_data = array();
		$update_data['user_class'] = $user_class;
		$update_data['class_period_validity'] = $user_class_period_validity;

		HttpDaoManager::getUserDao()->update($update_data, $user_info['id']);
	}
	
	public function buy($buy_info){
		$ticket = '';
		$priceDao = HttpDaoManager::getProductDao();
		$ticketServer  =HttpServerManager::getTicketServer();
		if (!empty($buy_info['use_number'])){
			$ticket=  $ticketServer->validation($buy_info['userId'], $buy_info['use_number']);
			if (!empty($ticket)){
				$ticketPrice = $priceDao->get($ticket['product_id']);
			}
			else{
				return USER_ERROR_11;
			}
		}
		
		$priceList =$priceDao->getListInId($buy_info['productId']);
		if (empty($priceList)){
			return USER_ERROR_12;
		}
		$pricePrice = $priceDao->getSumPrice($buy_info['productId']);
		$priceDiscount = $priceDao->getSumDiscount($buy_info['productId']);
		$Order['order_type'] = ORDER_TYPE_1;
		$Order['user_id'] = $buy_info['userId'];
		$Order['order_amount'] = $pricePrice;
		$Order['discount_money'] = 	$priceDiscount;
		$Order['monthly_start_date'] = $buy_info['monthly_start_date'];
		if (!empty($ticket)){
			$Order['ticket_id'] = $ticket['id'];
		}
		$ticketPrice1 = 0;
		if (!empty($ticketPrice)){
			$Order['ticket_money'] = $ticketPrice['price'];
			$ticketPrice1 = $ticketPrice['price'];
		}
		$tmp = array();
		foreach ($priceList as $v){
			$tmp[]='|'.$v['id'].'|';
		}
		$Order['product_id']= implode(',',$tmp);
		$Order['add_user'] = $_SESSION['user']['english_name'];
		$orderId = $this->add($Order);
		if (!empty($ticket)){
			$ticketServer->uses($ticket['id'],$orderId);
		}
		$orderData = HttpDaoManager::getOrderDao()->get($id);
		$user = HttpDaoManager::getUserDao()->get($_SESSION['user']['id']);
		
		$userMoney = $orderData['user_money'];
		$data['realPay'] =  $pricePrice - $priceDiscount - $ticketPrice1-$userMoney;
		$data['orderId'] = $orderId;
		return $data;
	}
	public function verifyOrder($id,$userId){
		$orderDao  = HttpDaoManager::getOrderDao();
		$orderData = $orderDao->searchData(array('id'=>$id,'user_id'=>$userId,'pay_status'=>PAY_STATUS_1));
		if (empty($orderData)){
			return false;
		}
		$payMoney = $orderData['order_amount']-$orderData['discount_money']-$orderData['ticket_money'];
		return $payMoney;
	} 
	public function userMoenyPay($payMoney,$userId){
		$userDao = HttpDaoManager::getUserDao();
		$userData =$userDao->get($userId);
		if ($userData['user_moeny']>=$payMoney){
			$balance = $userData['user_moeny'] - $payMoney;
			$userDao->update(array('user_moeny'=>$balance), $userData['id']);
			$orderData1['user_money'] = $payMoney;
			$orderData1['pay_type'] = PAY_TYPE_BALANCE;
			$userMoenyLog['type'] = USER_LOG_PAY;
			$userMoenyLog['moeny'] = -$payMoney ;
			$userMoenyLog['time'] = time();
			$userMoenyLog['add_user']  = $userData['english_name'];
			$userMoenyLog['user_id'] = $userId;
			HttpDaoManager::getUserMoneyLogDao()->add($userMoenyLog);
			return $orderData1;
		}
		return false;
		
	}
	public function balancePay($id,$userId){
		$payMoney = $this->verifyOrder($id, $userId);
		if ($payMoney===false){
			return USER_ERROR_13;
		}
		else{
			$orderData1 = $this->userMoenyPay($payMoney, $userId);
			if ($orderData1===false){
				return USER_ERROR_14;
			}
			else{	
				$this->pay($orderData1, $id);
				$_SESSION['pay_order_type'] = ORDER;
				$_SESSION['pay_order_id'] = $id;
				$payData = array();
				$payData= $orderData;
				$payData['money']=$orderData1['user_money'];
				$payData['pay_type']=PAY_TYPE_BALANCE;
				HttpServerManager::getPayLogServer()->addForOrder($payData);				
			}
			return true;
		}
	}
	public function remittance($id,$userId){
		$orderDao  = HttpDaoManager::getOrderDao();
		$orderData = $orderDao->searchData(array('id'=>$id,'user_id'=>$userId,'pay_status'=>PAY_STATUS_1));
		if (empty($orderData)){
			return USER_ERROR_13;
		}
		HttpDaoManager::getOrderDao()->update(array('pay_type'=>PAY_TYPE_REMIT), $id);
		return TRUE;
	}
	public function  userGetByid($id,$userId){
		$data =  HttpDaoManager::getOrderDao()->searchData(array('id'=>$id,'user_id'=>$userId,'pay_status'=>PAY_STATUS_1));
		if(empty($data)){
			return PAY_ERROR_1;
		}
		$priceDao = HttpDaoManager::getProductDao();
		$productId = strtr($data['product_id'],array('|'=>''));
		$pricePrice = $priceDao->getSumPrice($productId);
		$priceDiscount = $priceDao->getSumDiscount($productId);
		$userMoney= $data['user_money'];//可能产生二次支付
		$onlineMoney = $data['online_money'];
		$data['realPay'] = $pricePrice - $priceDiscount - $data['ticket_money']-$userMoney-$onlineMoney;
		$data['orderId'] = $data['id'];
		return $data;
	}
	public function validBalancePaySome($userMoeny,$id,$userId){
		if (!empty($userMoeny)){
			$userData = HttpDaoManager::getUserDao()->get($userId);
			if ($userData['user_moeny']<$userMoeny){
				return USER_ERROR_14;
			}
			$payMoney = $this->verifyOrder($id,$userId);
			if ($_POST['user_moeny']>0&&$payMoney>$_POST['user_moeny']){
				$data['user_money']=$userMoeny;
				HttpDaoManager::getOrderDao()->update($data,$id);
				HttpServerManager::getOrderServer()->userMoenyPay($_POST['user_moeny'], $userId);
				return BALANCE_PAY_SUCCESS;
			}
		}
	}
	public function alipay($orderData){
		$data = $orderData;
		$data['WIDsubject'] = '购买课程';
		//$data['online_money'] =0.1;
 		$data['online_money'] = $orderData['order_amount']-$orderData['user_money']-$orderData['discount_money']-$orderData['ticket_money'];
		$data['WIDbody'] ='购买课程';
		$pay_log_data = $data;
		$pay_log_data['money'] = $data['online_money'];
		$pay_log_data['pay_type'] = PAY_TYPE_ALIPAY;
		$pay_log_id = HttpServerManager::getPayLogServer()->addForOrder($pay_log_data);

		$data['id']=date('YmdHis').'_O'.$orderData['id'];
		$data['pay_log_id'] = $pay_log_id;
		$alipay  = new Alipay();
		$html =  $alipay->pay($data);
		$tmp['pay_type'] = PAY_TYPE_ALIPAY;
		
		$pos = stripos($data['id'], 'O');
		if($pos<0){
			return '支付失败';
		}
		$order_id = substr($data['id'],$pos+1);		
		HttpDaoManager::getOrderDao()->update($tmp, $order_id);
		//增加支付日志
		return $html;
	}
	
	public function  tenpay($orderData){
		$data = $orderData;
		$data['WIDsubject'] = '购买课程';
		$data['online_money'] = $orderData['order_amount']-$orderData['user_money']-$orderData['discount_money']-$orderData['ticket_money'];
		//$data['online_money'] = '0.1';
		$data['WIDbody'] ='购买课程';
		$pay_log_data = $data;
		$pay_log_data['money'] = $data['online_money'];
		$pay_log_data['pay_type'] = PAY_TYPE_TENPAY;
		$pay_log_id = HttpServerManager::getPayLogServer()->addForOrder($pay_log_data);
			
		$data['pay_log_id'] = $pay_log_id;
		$data['id']=date('YmdHis').'_O'.$orderData['id'];	
		$tenpay  = new Tenpay();
		$html =  $tenpay->pay($data);
		$tmp['pay_type'] = PAY_TYPE_TENPAY;
		
		$pos = stripos($data['id'], 'O');
		if($pos<0){
			return '支付失败';
		}
		$order_id = substr($data['id'],$pos+1);		
		HttpDaoManager::getOrderDao()->update($tmp, $order_id);

		return $html;
	}
	public function alipayCharge($data){
		$data['WIDsubject'] = '课程购买';
		$data['online_money'] = $data['online_money'];
		$data['WIDbody'] ='课程购买';
		
		$pay_log_data = $data;
		$pay_log_data['money'] = $data['online_money'];
		$pay_log_data['pay_type'] = PAY_TYPE_ALIPAY;
		$pay_log_id = HttpServerManager::getPayLogServer()->addForSaving($pay_log_data);
		$data['pay_log_id'] = $pay_log_id;		
		$data['id'] = date('YmdHis').'_C'.$pay_log_id;
		$alipay  = new Alipay();
		$html =  $alipay->pay($data);
		//增加支付日志
		return $html;
	}
	
	public function  tenpayCharge($data){
		$data['WIDsubject'] = '课程购买';
		$data['online_money'] = $data['online_money'];
		$data['WIDbody'] ='课程购买';
		
		$pay_log_data = $data;
		$pay_log_data['money'] = $data['online_money'];
		$pay_log_data['pay_type'] = PAY_TYPE_TENPAY;
		$pay_log_id = HttpServerManager::getPayLogServer()->addForSaving($pay_log_data);
		$data['pay_log_id'] = $pay_log_id;		
		$data['id'] = date('YmdHis').'_C'.$pay_log_id;
		$tenpay  = new Tenpay();
		$html =  $tenpay->pay($data);
		return $html;
	}
	
	public function updatePayInfo($data){//回调函数重写
		$order_pay_log = HttpDaoManager::getPayLogDao()->get($data['pay_log_id']);
		if(empty($order_pay_log)){
			return '支付失败';
		}else{
			if($order_pay_log['type']==ORDER){//更新订单已经其他任务
				$pos = stripos($data['id'], 'O');
				if($pos<0){
					return '支付失败';
				}
				$order_id = substr($data['id'],$pos+1);
				$order_info = HttpDaoManager::getOrderDao()->get($order_id);
				if(empty($order_info)){
					return '支付失败';
				}
				if($order_pay_log['status'] == PAY_STATUS_CONFIRMED){
					return '订单已支付,无需支付,谢谢';
				}
				if($order_pay_log['status'] == PAY_STATUS_UNCOFIRMED){
					$pay_log_data = array();
					$pay_log_data['status']=PAY_STATUS_CONFIRMED;
					$pay_log_data['id']=$data['pay_log_id'];
					HttpDaoManager::getPayLogDao()->update($pay_log_data, $pay_log_data['id']);
				}
					
				if($order_info['pay_status'] == PAY_STATUS_1){//未支付成功，更改支付状态，并且赠送课程
					$orderData = array();
					$orderData['online_money'] = $data['total_fee']/100;
					$this->pay($orderData, $order_id);//
					$_SESSION['pay_order_type'] = ORDER;
					$_SESSION['pay_order_id'] = $order_id;					
				}			
			}
			
			if($order_pay_log['type']==SAVING){//更新充值任务
				$pos = stripos($data['id'], 'C');
				$charge_id = substr($data['id'],$pos+1);
				if($order_pay_log['status'] == PAY_STATUS_UNCOFIRMED){
					$pay_log_data = array();
					$pay_log_data['status']=PAY_STATUS_CONFIRMED;
					$pay_log_data['id']=$data['pay_log_id'];
					
					$_SESSION['pay_order_type'] = $order_pay_log['type'];
					$_SESSION['pay_order_id'] = $data['pay_log_id'];					
					HttpDaoManager::getPayLogDao()->update($pay_log_data, $pay_log_data['id']);
					//更改用户账户的余额状态
					//更改用户余额状况，只能更改一次
					$change_money = $order_pay_log['amount'];
					$user_id = $order_pay_log['user_id'];
					HttpServerManager::getUserServer()->changeUserMoney($user_id, $change_money);
				}
			}
		}
		
		return true;
	}
	
	public function updateNotifyPayInfo($out_id,$money){//回调函数重写
		$pos_o = stripos($out_id, 'O');
		$pos_c = stripos($out_id, 'C');
		if($pos_o>0){
			$order_id = substr($out_id,$pos_o+1);
			$order_info = HttpDaoManager::getOrderDao()->get($order_id);
			$where  = array();
			$where['target_sn']= $order_info['order_no'];
			$where['status'] = PAY_STATUS_UNCOFIRMED;
			//$where['amount'] = $money;
			$where['type'] = ORDER;//更改为PAY_ORDER
			$order_pay_log = HttpDaoManager::getPayLogDao()->searchList($where,'order by id desc',1);//最新的一个请求记录
			if($order_pay_log['status'] == PAY_STATUS_UNCOFIRMED){
				$pay_log_data = array();
				$pay_log_data['status']=PAY_STATUS_CONFIRMED;
				$pay_log_data['id']=$order_pay_log['id'];
				HttpDaoManager::getPayLogDao()->update($pay_log_data, $pay_log_data['id']);
			}
		
			if($order_info['pay_status'] == PAY_STATUS_1){//未支付成功，更改支付状态，并且赠送课程
				$orderData = array();
				$orderData['online_money'] = $money;
				$this->pay($orderData, $order_id);//
				$_SESSION['pay_order_type'] = ORDER;
				$_SESSION['pay_order_id'] = $order_id;				
			}
			$this->complete($order_id);
		}
		if($pos_c>0){
			$order_id = substr($out_id,$pos_c+1);
			$order_pay_log = HttpDaoManager::getPayLogDao()->get($order_id);//最新的一个请求记录
			if($order_pay_log['status'] == PAY_STATUS_UNCOFIRMED){
				$pay_log_data = array();
				$pay_log_data['status']=PAY_STATUS_CONFIRMED;
				$pay_log_data['id']=$order_id;
				HttpDaoManager::getPayLogDao()->update($pay_log_data, $pay_log_data['id']);
				//更改用户余额状况，只能更改一次
				$change_money = $order_pay_log['amount'];
				$user_id = $order_pay_log['user_id'];
				HttpServerManager::getUserServer()->changeUserMoney($user_id, $change_money);
				$_SESSION['pay_order_type'] = SAVING;
				$_SESSION['pay_order_id'] = $order_id;				
			}
		}
		
		return true;
	}
}
?>